package ch.netcetera.planningpoker.server.dao;

import ch.netcetera.planningpoker.server.model.Game;

import com.google.appengine.api.datastore.EntityNotFoundException;
import com.googlecode.objectify.Key;

public class GameDao extends ObjectifyDao<Game> {

    public Long persistGame(Game game) {
        Key<Game> key = put(game);
        return key.getId();
    }

    public Game findGame(Long id) {
        try {
            return get(id);
        } catch (EntityNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public Boolean isGameExisting(String gameTitle) {
        Game lookup = new Game(gameTitle);
        Game result = getByExample(lookup);
        return result != null;
    }

}
